function result = maximum_match (c1, c2, rad)

    C = contingency_matrix(c1, c2, rad);	  %form contingency matrix	
 	n = length(c1.bmus); %data quantity

%C = c1;
    result = 0;
    while min (size(C, 1), size(C, 2))
        [i, j] = find_max_entry(C);
        result = result + C(i, j);    
        C = delete_row_col(C, i, j);
    end
    result = result  / n;
    

function [i, j] = find_max_entry(C)
    [values, rows] = max(C);
    if size(C,1) == 1
        % es un vector fila por lo que el valor de j es lo retornado por la función max
        % y el valor de i es 1.
        i = 1;
        j = rows;
    else
        [values, j] = max(values);
        i = rows(j);
    end
    
    
function m = delete_row_col (C, i, j)
    
    size_C = size(C);
    size_m = size_C - 1;
    m = zeros(size_m);    
    
    % Borrar la fila y la columna 
    m(1:i-1, 1:j-1) = C(1:i-1, 1:j-1);
    m(1:i-1, j:size_m(2)) = C(1:i-1, j+1:size_C(2));
    m(i:size_m(1), 1:j-1) = C(i+1:size_C(1), 1:j-1);
    m(i:size_m(1), j:size_m(2)) = C(i+1:size_C(1), j+1:size_C(2));
    
